﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Rocket.Windows.Framework;
using System.Linq.Expressions;
using Rocket.Data;
using Rocket.Core;
using Rocket.Bll.Models;

namespace MainForm.ChildControls
{
    public partial class ReaderApplicationFilter : RocketBaseData, IFormDataFilter<ReaderApplication>
    {
        private ComboBox comboBoxNameFilter;
        private Label labelFilter;

        public ReaderApplicationFilter()
        {
            InitializeComponent();
        }

        private void InitializeComponent()
        {
            this.comboBoxNameFilter = new System.Windows.Forms.ComboBox();
            this.labelFilter = new System.Windows.Forms.Label();
            this.SuspendLayout();
            // 
            // comboBoxNameFilter
            // 
            this.comboBoxNameFilter.FormattingEnabled = true;
            this.comboBoxNameFilter.Items.AddRange(new object[] {
            "All Codes",
            "Code from - 001 to - 005",
            "Code from - 006 to - 010",
            "Code from - 010 to - 015",
            "Code from - 016 to - 020"});
            this.comboBoxNameFilter.Location = new System.Drawing.Point(97, 3);
            this.comboBoxNameFilter.Name = "comboBoxNameFilter";
            this.comboBoxNameFilter.Size = new System.Drawing.Size(205, 21);
            this.comboBoxNameFilter.TabIndex = 0;
            // 
            // labelFilter
            // 
            this.labelFilter.AutoSize = true;
            this.labelFilter.Location = new System.Drawing.Point(3, 6);
            this.labelFilter.Name = "labelFilter";
            this.labelFilter.Size = new System.Drawing.Size(85, 13);
            this.labelFilter.TabIndex = 1;
            this.labelFilter.Text = "Code Start With:";
            // 
            // ReaderApplicationFilter
            // 
            this.Controls.Add(this.labelFilter);
            this.Controls.Add(this.comboBoxNameFilter);
            this.Name = "ReaderApplicationFilter";
            this.Size = new System.Drawing.Size(630, 28);
            this.ResumeLayout(false);
            this.PerformLayout();

        }

        public Expression<Func<ReaderApplication, bool>> GetWhereCondition()
        {
            // All Codes
            // Code from - 001 to - 005
            // Code from - 006 to - 010
            // Code from - 010 to - 015
            // Code from - 016 to - 020
            int i = this.comboBoxNameFilter.SelectedIndex;
            Expression<Func<ReaderApplication, bool>> expression = null;
            switch (i)
            {
                case 0:
                    {
                        expression = x => (x.Code.CompareTo("0") > 0);
                        break;
                    }
                case 1:
                    {
                        expression = x => ((x.Code.CompareTo("000") > 0 ) && (x.Code.CompareTo("006") < 0));
                        break;
                    }
                case 2:
                    {
                        expression = x => ((x.Code.CompareTo("005") > 0) && (x.Code.CompareTo("011") < 0));
                        break;
                    }
                case 3:
                    {
                        expression = x => ((x.Code.CompareTo("010") > 0) && (x.Code.CompareTo("016") < 0));
                        break;
                    }
                case 4:
                    {
                        expression = x => ((x.Code.CompareTo("015") > 0) && (x.Code.CompareTo("021") < 0));
                        break;
                    }
            }
            return expression;
        }

        public Expression<Func<ReaderApplication, bool>> GetFilterExpression()
        {
            return GetWhereCondition();
        }

        public string GridViewGroupBoxName { get; set; }
        public string ManagerGroupBoxName { get; set; }
        public string GroupBoxName { get; set; }
    }
}
